{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bs4 import BeautifulSoup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "doc = BeautifulSoup(open('metadata'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "trs = doc.find_all('tr')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Anonymous Pony\n",
      "\n",
      "\n",
      "\n",
      "(Jan 17, 2020)\n",
      "['76.71', '86.69', '66.72', '78.46']\n",
      "---\n",
      "Anonymous Python\n",
      "\n",
      "\n",
      "\n",
      "(Dec 25, 2019)\n",
      "['66.41', '83.52', '51.85', '73.60']\n",
      "---\n",
      "Anonymous Groundhog\n",
      "\n",
      "\n",
      "\n",
      "(Dec 25, 2019)\n",
      "['67.23', '82.09', '54.32', '71.01']\n",
      "---\n",
      "BERT-PAIR\n",
      "https://www.aclweb.org/anthology/D19-1649.pdf\n",
      "https://github.com/thunlp/fewrel\n",
      "THUNLP, Tsinghua University\n",
      "(Nov 3, 2019)\n",
      "['67.41', '78.57', '54.89', '66.85']\n",
      "---\n",
      "Proto-ADV (CNN)\n",
      "https://www.aclweb.org/anthology/D19-1649.pdf\n",
      "https://github.com/thunlp/fewrel\n",
      "THUNLP, Tsinghua University\n",
      "(Nov 3, 2019)\n",
      "['42.21', '58.71', '28.91', '44.35']\n",
      "---\n",
      "Proto-ADV (BERT)\n",
      "https://www.aclweb.org/anthology/D19-1649.pdf\n",
      "https://github.com/thunlp/fewrel\n",
      "THUNLP, Tsinghua University\n",
      "(Nov 3, 2019)\n",
      "['41.90', '54.74', '27.36', '37.40']\n",
      "---\n",
      "Proto-BERT\n",
      "\n",
      "\n",
      "\n",
      "(Nov 3, 2019)\n",
      "['40.12', '51.50', '26.45', '36.93']\n",
      "---\n",
      "Proto-CNN\n",
      "\n",
      "\n",
      "\n",
      "(Nov 3, 2019)\n",
      "['35.09', '49.37', '22.98', '35.22']\n",
      "---\n"
     ]
    }
   ],
   "source": [
    "metafile = open('meta_da.csv', 'w')\n",
    "for tr in trs:\n",
    "    tds = tr.find_all('td')\n",
    "    assert(len(tds) == 5)\n",
    "    meta = tds[0]\n",
    "    name = meta.get_text().split('\\n')[0].strip()\n",
    "    if len(name) == 0:\n",
    "        name = meta.get_text().split('\\n')[1].strip()\n",
    "    print(name)\n",
    "    hrefs = tr.find_all('a')\n",
    "    paper = ''\n",
    "    code = ''\n",
    "    for href in hrefs:\n",
    "        if href.get_text() == '[paper]':\n",
    "            paper = href['href']\n",
    "        elif href.get_text() == '[code]':\n",
    "            code = href['href']\n",
    "        else:\n",
    "            raise Exception('Unknown href')\n",
    "    print(paper)\n",
    "    print(code)\n",
    "    strongs = tr.find_all('strong')\n",
    "    inst = ''\n",
    "    if len(strongs) > 0:\n",
    "        inst = strongs[0].get_text()\n",
    "    print(inst)\n",
    "    \n",
    "    try:\n",
    "        date = meta.get_text().split('\\n')[-2].strip()\n",
    "    except:\n",
    "        date = ''\n",
    "    print(date)\n",
    "    \n",
    "    pf = [tds[1].get_text(), tds[2].get_text(), tds[3].get_text(), tds[4].get_text()]\n",
    "    print(pf)\n",
    "    \n",
    "    print('---')\n",
    "    \n",
    "    metafile.write(\"{}\\t{}\\t{}\\t{}\\t{}\\t{}\\t{}\\t{}\\t{}\\n\".format(name, paper, code, inst, date, pf[0], pf[1], pf[2], pf[3]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "metafile.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
